﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Castle.Windsor;
using Castle.MicroKernel.Registration;
using Tanmia.Basis.ViewInterface;
using Tanmia.Basis.ServiceInterface;
using System.Windows.Controls.Primitives;
using Microsoft.Practices.ServiceLocation;
using Tanmia.Basis.Prism;
using Tanmia.Basis;
using Tanmia.Warehouse.Core;

namespace SaryaAccounting
{
    /// <summary>
    /// Interaction logic for MainWindowView.xaml
    /// </summary>
    /// <remarks>
    /// The Export attribute does not use a name like the other views need.  <see cref="ItemView"/>.
    /// The reason for this is because this view is never naviagted to, instead it is created in the
    /// application <see cref="Bootstrapper"/>.
    /// </remarks>
    public partial class MainWindowView : BaseWindow, IShellView
    {
        public MainWindowView(MainWindowViewModel viewModel)
        {
            InitializeComponent();
            this.DataContext = viewModel;
        }

        #region IShellView Members

        public void ShowWaitCursor(bool status)
        {
            Cursor = status ? Cursors.Wait : Cursors.Arrow;
        }

        public void UpdateStatus(string status)
        {
            tbStatus.Text = status;
        }

        #endregion

        IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();

        private void btnBranchAdd_Click(object sender, RoutedEventArgs e)
        {
            regionManager.NavigateToEditor("BranchEditor", new Branch());
        }

        private void btnBranchBrowse_Click(object sender, RoutedEventArgs e)
        {
            regionManager.RequestNavigate(Constants.RegionMain, "BranchBrowser");
        }

        private void btnUnitAdd_Click(object sender, RoutedEventArgs e)
        {
            regionManager.NavigateToEditor("UnitEditor", new Unit());
        }

        private void btnUnitBrowser_Click(object sender, RoutedEventArgs e)
        {
            regionManager.RequestNavigate(Constants.RegionMain, "UnitBrowser");
        }

        private void btnStoreBrowser_Click(object sender, RoutedEventArgs e)
        {
            regionManager.RequestNavigate(Constants.RegionMain, "StoreBrowser");
        }

        private void btnSectionTypeBrowser_Click(object sender, RoutedEventArgs e)
        {
            regionManager.RequestNavigate(Constants.RegionMain, "SectionTypeBrowser");
        }

        private void btnSectionTypeEditor_Click(object sender, RoutedEventArgs e)
        {
            regionManager.NavigateToEditor("SectionTypeEditor", new SectionType());
        }

        private void btnSectionEditor_Click(object sender, RoutedEventArgs e)
        {
            regionManager.NavigateToEditor("SectionEditor", new Tanmia.Warehouse.Core.Section());
        }

        private void btnSectionTreeBrowser_Click(object sender, RoutedEventArgs e)
        {
            regionManager.RequestNavigate(Constants.RegionMain, "SectionTreeBrowser");
        }

        private void MaxAndNormalButton_Toggle(object sender, RoutedEventArgs e)
        {
            if (MaxAndNormalButton.IsChecked.HasValue && MaxAndNormalButton.IsChecked.Value)
                MaximizeWindow();
            else
                NormalizeWindow();
        }

        private void MinButton_Click(object sender, RoutedEventArgs e)
        {
            MinimizeWindow();
        }

        private void CaptionBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 1)
                DraggingWindow(e);
            else if (e.ClickCount == 2)
                if (MaxAndNormalButton.IsChecked.Value)
                    MaxAndNormalButton.IsChecked = false;
                else
                    MaxAndNormalButton.IsChecked = true;
        }
    }
}
